<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    
<script type="text/javascript">
	$(function() {
		var ue1 = UE.getEditor('desc_editor',{initialFrameWidth:900});
    	var ue2 = UE.getEditor('buynote_editor',{initialFrameWidth:900});
    	
    	$("#select-scene-btn").click(function() {
    		var modal = $.bmodal({
    			title:"选择景区",
    			url:"/scene/dialog.htm",
    			buttons:[{
    				text:"保存",
    				click:function() {
    					var checkedScene = $("input[name='sceneId']:checked");
    					var sceneId = checkedScene.val();
    					var sceneName = checkedScene.parent().next().text();
    					$("#ticket-form").find("input[name='scenicId']").val(sceneId);
    					$("#ticket-form").find("input[name='scene-name-display']").val(sceneName);
    					modal.modal("hide");
    				}
    			},{
    				text:"关闭",
    				click:function() {
    					modal.modal("hide");
    				}
    			}]
    		})
    	})
    	
    	$("#select-distributor-btn").click(function() {
    		var modal = $.bmodal({
    			title:"选择供应商",
    			url:"/distributor/dialog.htm",
    			buttons:[{
    				text:"保存",
    				click:function() {
    					var check = $("#distributor-table").find("input[name='distributorId']:checked");
    					var checkId = check.val();
    					if(checkId==null)
    						alert("请选择供应商！！");
    					else {
    						var distributorName = check.parent().next().text();
        					$("#ticket-form").find("input[name='distributor-name-display']").val(distributorName);
    						$("#ticket-form").find("input[name='distributorId']").val(checkId);
    						modal.modal("hide");
    					}
    				}
    			},{
    				text:"关闭",
    				click:function() {
    					modal.modal("hide");
    				}
    			}]
    		})
    	})
    	
    	var id="${ticket.ticketInfoId}";
    	var url="/ticket/add.htm";
    	if(id!=null&&id!="") {
    		url="/ticket/update.htm";
    		$("#dictTicketType").val("${ticket.dicTicketType}");
    		var radios = $("#ticket-form").find("input[type=radio][name=isok]");
    		radios.removeAttr("checked");
    		var isok = "${ticket.isok}";
    		if(isok=="0")
    			radios[1].checked = true;
    		else if(isok=="1")
    			radios[0].checked = true;
    	}
    	
    	$("#ticket-save-btn").click(function() {
    		$.ajax({
    			url:url,
    			type:"post",
    			data:$("#ticket-form").serialize(),
    			dataType:"json"
    		}).done(function(data){
    			alert(data.msg);
    			if(data.isSuccess) {
    				window.location = window.location;
    			}
    		})
    	})
    	
    	$("#ticket-save-return-btn").click(function() {
    		window.location = window.location;
    	})
    	
    	$("#ticket-submit-btn").click(function() {
    		$.ajax({
    			url:url,
    			type:"post",
    			data:$("#ticket-form").serialize()+"&dicTicketStatus=1",
    			dataType:"json"
    		}).done(function(data){
    			alert(data.msg);
    			if(data.isSuccess) {
    				window.location = window.location;
    			}
    		})
    	})
	})
</script>    

<div class="ch-container">

<div class="row">
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-content">
                <form class="form-inline" role="form" id="ticket-form">
                	<input type="hidden" name="ticketInfoId" value="${ticket.ticketInfoId }">
                    <div class="form-group col-md-6">
                        <label>商品名称：</label>
                        <input name="name" type="text" class="form-control" value="${ticket.name}">
                    </div>
                    <div class="form-group col-md-6">
                        <label>所在景区：</label>
                        <input name="scene-name-display" readonly="readonly" type="text" class="form-control" value="${ticket.scene.name }">
                        <input type="hidden" name="scenicId" value="${ticket.scenicId }">
                        <a href="javascript:;" class="btn btn-default" id="select-scene-btn">选择</a>
                    </div>
                    <div class="clearfix"></div><br>
                    <div class="form-group col-md-12">
                        <label>检索关键字：</label>
                        <input name="keyWords" type="text" class="form-control" value="${ticket.keyWords }">
                    </div>
                    <div class="clearfix"></div><br>
                    <div class="form-group col-md-6">
                        <label>票品分类：</label>
                        <select id="dictTicketType" name="dicTicketType" class="form-control">
                        	<option value="">--请选择--</option>
                        	<c:forEach items="${types }" var="type">
                        		<option value="${type.dictionaryId }">${type.name }</option>
                        	</c:forEach>
                        </select>
                    </div>
                    <div class="form-group col-md-6">
                        <label>所属分销商：</label>
                        <input name="distributor-name-display" readonly="readonly" type="text" class="form-control" value="${ticket.distributor.name }">
                        <input name="distributorId" type="hidden" class="form-control" value="${ticket.distributorId }">
                        <a href="javascript:;" class="btn btn-default" id="select-distributor-btn">选择</a>
                    </div>
                    <div class="clearfix"></div><br>
                    <div class="form-group col-md-12">
                       <ul class="thumbnails gallery">
                       </ul> 
                    </div>
                    <div class="form-group col-md-4">
                        <label>商品进价：</label>
                        <input name="buyinPrice" type="text" class="form-control" value="${ticket.buyinPrice }">元
                    </div>
                    <div class="form-group col-md-4">
                        <label>市场价：</label>
                        <input name="listPrice" type="text" class="form-control" value="${ticket.listPrice }">元
                    </div>
                    <div class="form-group col-md-4">
                        <label>库存数量：</label>
                        <input name="inventory" type="text" class="form-control" value="${ticket.inventory }">
                    </div>
                    <div class="clearfix"></div><br>
                    <div class="form-group col-md-6">
	                    <label>有效时间：</label>
	                    <input value="${ticket.fromTime_display }" name="fromTime" type="text" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="form-control"/>
	                    <label>至</label>
	                    <input value="${ticket.endTime_display }" name="endTime" type="text" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="form-control"/>
	                </div>
                    <div class="clearfix"></div><br>
                    <div class="form-group col-md-3">
                        <label>状态：</label>
                       	<label class="radio-inline">
		                    <input type="radio" name="isok" value="1" checked="checked">启用
		                </label>
		                <label class="radio-inline">
		                    <input type="radio" name="isok" value="0">禁用
		                </label>
                    </div>
                    <div class="clearfix"></div><br>
                    <div class="form-group">
                        <label>票品介绍：</label>
                        <!-- 加载编辑器的容器 -->
						<script id="desc_editor" name="description" type="text/plain">
						${ticket.description }
						</script>
                    </div>
                    <div class="clearfix"></div><br>
                    <div class="form-group">
                        <label>订购须知：</label>
                        <!-- 加载编辑器的容器 -->
						<script id="buynote_editor" name="buyNote" type="text/plain">
						${ticket.buyNote }
						</script>
                    </div>
                    <div class="clearfix"></div><br>
                    <button type="button" class="btn btn-default" id="ticket-save-btn">保存</button>
                    <button type="button" class="btn btn-default" id="ticket-submit-btn">提交</button>
                    <button type="button" class="btn btn-default" id="ticket-save-return-btn">返回</button>
                </form>

            </div>
        </div>
    </div>
    <!--/span-->

</div><!--/row-->
</div>